﻿using System;
using DevExpress.XtraGrid.Views.Grid;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using System.Drawing;
using DevExpress.XtraGrid.Columns;
using System.Data;
using DevExpress.XtraGrid.Views.Base;
using System.Collections;
using DevExpress.Data;
using System.Reflection;

namespace QLSinhVienThucTap
{
    class Utils
    {
    }
    public static class AppGridView
    {
        /// <summary>
        /// Init GridView
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="autoFilter"></param>
        /// <param name="multiSelect"></param>
        /// <param name="selectMode"></param>
        /// <param name="detailButton"></param>
        /// <param name="groupPanel"></param>
        public static void InitGridView(GridView grid, bool autoFilter, bool multiSelect,
            GridMultiSelectMode selectMode, bool detailButton, bool groupPanel,
            bool showFooter, bool showIndicator)
        {
            //Show filter
            grid.OptionsView.ShowAutoFilterRow = autoFilter;
            //Show multi select
            grid.OptionsSelection.MultiSelect = multiSelect;
            //Show multi select mode
            grid.OptionsSelection.MultiSelectMode = selectMode;
            //Show detail button
            grid.OptionsView.ShowDetailButtons = detailButton;
            grid.OptionsView.ShowChildrenInGroupPanel = detailButton;
            grid.OptionsDetail.ShowDetailTabs = detailButton;
            //Show group panel
            grid.OptionsView.ShowGroupPanel = groupPanel;
            //Show footer
            grid.OptionsView.ShowFooter = showFooter;
            grid.OptionsView.ShowIndicator = showIndicator;

            for (int i = 0; i < grid.Columns.Count; i++)
                grid.Columns[i].Visible = false;
        }

        /// <summary>
        /// Read only gridview
        /// </summary>
        /// <param name="gridVeiw"></param>
        public static void ReadOnlyGridView(GridView gridVeiw)
        {
            gridVeiw.OptionsBehavior.Editable = false;
        }

        /// <summary>
        /// Show field with caption, width
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="fieldName"></param>
        /// <param name="caption"></param>
        /// <param name="width"></param>
        public static void ShowField(GridView grid, string[] fieldName, string[] caption)
        {
            grid.Columns.Clear();
            grid.OptionsView.ColumnAutoWidth = true;
            GridColumn[] columns = new GridColumn[fieldName.Length];
            for (int i = 0; i < fieldName.Length; i++)
            {
                columns[i] = new GridColumn();
                columns[i].VisibleIndex = i;
                columns[i].Visible = true;
                columns[i].FieldName = fieldName[i];
                columns[i].Caption = caption[i];
                columns[i].OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
            }
            grid.Columns.AddRange(columns);
        }
    }

    public class SaveChangeEventArgs : EventArgs
    {
        public bool IsNew { get; private set; }

        public SaveChangeEventArgs(bool isNew)
        {
            IsNew = isNew;
        }

    }
}
